package com.wl.thread.demo03;

/**
 * 线程停止
 */
public class TestThreadStop implements Runnable{
    private boolean  flag = true;
    @Override
    public void run() {
        int i  = 0;
        while (flag) {
            System.out.println("run..."+ i++);
        }
    }

    public void stop(){
        this.flag = false;
    }

    public static void main(String[] args) {
        TestThreadStop testThreadState = new TestThreadStop();
        new Thread(testThreadState).start();

        for (int i = 0; i < 1000; i++) {
            System.out.println("main..."+i);
            if (i == 900){
                testThreadState.stop();
                System.out.println("线程停止");
            }
        }
    }
}
